﻿using System.Windows.Forms;
using System.Data;

namespace Mota.XMLControls
{
    /// <summary>
    /// Represent WebBrowser control based on WinForms WebBrowser
    /// </summary>
    public class DXGuiWebBrowser:GuiWebBrowser
    {
        /// <summary>
        /// Create WinForms WebBrowser control
        /// </summary>
        public DXGuiWebBrowser()
        {
            visualControl = new WebBrowser();
        }
        /// <summary>
        /// SET|GET WebBrowser Text property
        /// </summary>
        public override string Text
        {
            get
            {
                return (visualControl as WebBrowser).Text;
            }
            set
            {
                (visualControl as WebBrowser).Text = value;
            }
        }
        /// <summary>
        /// Call WebBrowser Navigate method and pass url path from main BindingSource value
        /// </summary>
        /// <param name="valueBinding">main BindingSource with current record values</param>
        public override void SetValue(object valueBinding)
        {
            if(valueBinding is BindingSource)
                (visualControl as WebBrowser).Navigate(((valueBinding as BindingSource).Current as DataRowView)[XmlAttributes["XmlAttribute"]].ToString());
        }
        /// <summary>
        /// dummy property
        /// </summary>
        public override object Binding
        {
            get
            {
                return null;
            }
            set
            {
            }
        }


        public override object GetValue()
        {
            return (this.visualControl as WebBrowser).Url;
        }
    }
}
